package com.zxl.manager.controller;

import com.google.gson.Gson;
import com.zxl.manager.entity.Order;
import com.zxl.manager.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by jimmy on 2017/7/16.
 */
@Controller
public class OrderController {

    @Autowired
    private OrderService orderService;

    private Gson gson = new Gson();

    @RequestMapping("/prodInx")
    public ModelAndView prodInx(){
        ModelAndView mv = new ModelAndView();
        mv.setViewName("/order/index");
        return mv;
    }

    @RequestMapping("/getAllOrd")
    @ResponseBody
    public String getAllOrd(Integer limit,Integer offset){
        Map<String, Object> resMap = new HashMap<>();
        List<Order> list = orderService.getAllOrder(limit,offset);
        Integer total = orderService.totalOrder();
        resMap.put("total",total);
        resMap.put("rows",list);
        String res = gson.toJson(resMap);
        return res;
    }

    @RequestMapping("/updOrd")
    @ResponseBody
    public String updOrd(String ids){
        Integer res = orderService.updOrder(ids);
        Map resMap = new HashMap();
        resMap.put("code","0");
        resMap.put("msg",res);
        return gson.toJson(resMap);
    }

}
